package com.mfs.proxy.test.longtcp;

import lombok.SneakyThrows;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class TargetServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(new InetSocketAddress("127.0.0.1", 8080));
        while (true) {
            Socket accept = serverSocket.accept();
            new Thread() {
                @SneakyThrows
                @Override
                public void run() {
                    while (true) {
                        InputStream inputStream = accept.getInputStream();
                        byte[] bytes = new byte[1024];
                        int read = inputStream.read(bytes);
                        String s = new String(bytes, 0, read);
                        System.out.println(s);
                        accept.getOutputStream().write(("hello " + s).getBytes());
                    }
                }
            }.start();

        }
    }
}
